package tech.aichan.AiQA.utils;

import org.springframework.security.core.context.SecurityContextHolder;
import tech.aichan.AiQA.model.entity.login.LoginUser;
import tech.aichan.AiQA.model.vo.UserVO;

/**
 * @author mengyu
 * @date 2024/06/04 11:19
 */
public class UserInfoUtil {
    public static Long getUserId(){
        LoginUser principal = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return principal.getUser().getId();
    }

    public static LoginUser getLoginUser(){
        return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    public static UserVO getUserVO(){
        LoginUser principal = (LoginUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return UserVO.getUserVO(principal.getUser());
    }

}
